package org.jeecg.modules.appuser.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.Date.DateUtil;
import org.jeecg.modules.appuser.constant.PayTypeConstant;
import org.jeecg.modules.appuser.entity.TbUserSqtDetail;
import org.jeecg.modules.appuser.entity.TbUserWallet;
import org.jeecg.modules.appuser.entity.TbUserWalletDetail;
import org.jeecg.modules.appuser.mapper.TbUserSqtDetailMapper;
import org.jeecg.modules.appuser.service.ITbUserSqtDetailService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.math.BigDecimal;
import java.util.*;

/**
 * @Description: tb_user_sqt_detail
 * @Author: jeecg-boot
 * @Date:   2020-05-18
 * @Version: V1.0
 */
@Service
public class TbUserSqtDetailServiceImpl extends ServiceImpl<TbUserSqtDetailMapper, TbUserSqtDetail> implements ITbUserSqtDetailService {

    @Override
    public Result<?> getUserSQTDetail(String user_id) {
        Map<String,Object> resultMap=new HashMap<>();
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("user_id",user_id);
        queryWrapper.ne("pay_from","产币");
        queryWrapper.orderByDesc("create_time");
        List<TbUserSqtDetail> tbUserSqtDetailList=  this.baseMapper.selectList(queryWrapper);
        resultMap.put("tbUserSqtDetailList",tbUserSqtDetailList);

        List<TbUserSqtDetail> daySqtDetailList=  this.baseMapper.selectDaySqtDetail(user_id);
        resultMap.put("daySqtDetailList",daySqtDetailList);
        return Result.ok(resultMap);
    }

    @Override
    public BigDecimal getUserSQTByToday(String user_id) {

        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("user_id",user_id);
       // queryWrapper.eq("pay_type", PayTypeConstant.PAYTYPE_INCOME);
        Calendar date = Calendar.getInstance();
        date.set(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DATE), 0, 0, 0);
        Calendar date1 = Calendar.getInstance();
        date1.set(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DATE), 23, 59, 59);
        queryWrapper.between("create_time",date.getTime(),date1.getTime());
        List<TbUserSqtDetail> tbUserSqtDetailList=  this.baseMapper.selectList(queryWrapper);
        BigDecimal totalPayNumber=new BigDecimal(0);
        if(null!=tbUserSqtDetailList&&tbUserSqtDetailList.size()>0){

            for (TbUserSqtDetail tbUserSqtDetail : tbUserSqtDetailList) {
                 BigDecimal payNumber= tbUserSqtDetail.getPayNumber();
                 if(tbUserSqtDetail.getPayType().equals("1")){
                     totalPayNumber=totalPayNumber.add(payNumber);
                 }else{
                     totalPayNumber=totalPayNumber.subtract(payNumber);
                 }

            }
        }
        return totalPayNumber;
    }
}
